<?php

use yii\helpers\Html;
use yii\grid\GridView;
use backend\helpers\ActionButton;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\FurnitureSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Каталог мебели и оборудования';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="container furniture-index">

    <h1 class="main-title"><?= Html::encode($this->title) ?></h1>

    <div class="action-menu action-menu__container">
        <div>
            <?= ActionButton::create('Добавить объект', 'createFurniture') ?>
        </div>
        <div>
            <?= ActionButton::dictionaryLink('Склады, места', 'furniture-place/index', 'browseFurniturePlace');?>
            <?= ActionButton::dictionaryLink('Типы мебели и оборудования', 'furniture-type/index', 'browseFurnitureType');?>
        </div>
    </div>

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

</div>

<div class="container contract-table-container">

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'tableOptions' => [
            'class' => 'table table-striped'
        ],
        'filterModel' => $searchModel,
        'columns' => [

            [
                'attribute' => 'id_type',
                'filter' => \backend\models\FurnitureType::getList(),
                'filterInputOptions' => ['class' => 'form-control form-control-sm'],
                'value' => 'type.title',
            ],
            [
                'label' => 'Изображение',
                'format' => 'raw',
                'contentOptions' => ['style' => 'width:270px; white-space: normal;'],
                'value' => function($model) {
                    return Html::img(
                        'https://storage.yandexcloud.net/' .  backend\models\Furniture::BUCKET_NAME . '/' . $model->scheme_img,
                        [
                            'alt'=>'',
                            'class' => 'img-thumbnail',
                            'style' => 'width:160px;'
                        ]
                    );
                },
            ],
            'brand',
            'color',
            //'dimensions_height',
            //'dimensions_width',
            //'dimensions_depth',
            'amount',

            [
                'class' => 'yii\grid\ActionColumn',
                'visibleButtons' =>
                [
                    'view' => Yii::$app->user->can('browseFurniture'),
                    'update' => Yii::$app->user->can('updateFurniture'),
                    'delete' => Yii::$app->user->can('deleteFurniture'),
                ]
            ],
        ],
    ]); ?>


</div>
